export function testAllSettled() {
  const resolved = Promise.resolve(42);
  const rejected = Promise.reject(-1);

  const allSettledPromise = Promise.allSettled([resolved, rejected]);

  allSettledPromise.then(function (results) {
    // 可辨识联合类型
    results.forEach((value) => {
      if (value.status == 'fulfilled') {
        //04-28 21:17:34.176   29480-29480  A03d00/JSAPP                   com.examp...lication  I     promise allSettled 42
        console.log('promise allSettled', value.value)
      } else {
        //04-28 21:17:34.176   29480-29480  A03d00/JSAPP                   com.examp...lication  I     promise allSettled -1
        console.log('promise allSettled', value.reason)
      }
    })
  });
}

export function testAll() {
  const resolved = Promise.resolve(1);
  const resolve1 = Promise.resolve('a');
  const rejectObj = { code: -1, msg: 'reject' }
  const reject = Promise.reject(rejectObj)
  const allPromise = Promise.all([resolved, resolve1, reject])
  allPromise.then((results) => {
    results.forEach((value) => {
      if (typeof value === 'number') {
        //04-28 21:35:22.194   2821-2821    A03d00/JSAPP                   com.examp...lication  I     promise all success number 1
        console.log('promise all success number', value)
      } else if (typeof value === 'string') {
        //04-28 21:35:22.194   2821-2821    A03d00/JSAPP                   com.examp...lication  I     promise all success string a
        console.log('promise all success string', value)
      }
    })

  }, (value) => {
    type RejectObj = typeof rejectObj
    const obj = value as RejectObj
    //04-28 21:54:26.398   7497-7497    A03d00/JSAPP                   com.examp...lication  I     promise all reject code: -1 ,msg: reject
    console.log("promise all reject", `code: ${obj.code} ,msg: ${obj.msg}`)
  }).catch((value) => {
    type RejectObj = typeof rejectObj
    const obj = value as RejectObj
    //04-28 22:00:30.546   8766-8766    A03d00/JSAPP                   com.examp...lication  I     promise all reject1 code: -1 ,msg: reject
    console.log('promise all reject1', `code: ${obj.code} ,msg: ${obj.msg}`)
  })
}

export function testNewPromise() {
  const promise1 = new Promise((resolve) => {
    setTimeout(() => {
      resolve('foo');
    }, 300);
  });

  promise1.then((value) => {
    console.log('testPromise', value);
    // Expected output: "foo"
  });

}

